/**
 * @file SolveEqu.h
 * @author shikang999@126.com
 * @brief 
 * @version 0.1
 * @date 2025-07-28
 * 
 * @copyright Copyright (c) 2025
 * 
 */
#pragma once
#include "BaseData.h"

//采用LLT求解线性方程组,即使方程歧义,也能求解
namespace Solver
{
class SolveEqu
{
public:
    SolveEqu();
    ~SolveEqu();

public:
    //求解方程组 (vA + I * r) * x = b. 如果vA为对称矩阵,优先调用solveLineEquForSymMatrix函数
    void solveLineEqu(const MatrixXd_t &vA, const VectorXd_t &b, VectorXd_t &x, const value_t r = 0);

    //求解方程组 (vA + I * r) * x = b. 这里要求vA为对称矩阵.
    void solveLineEquForSymMatrix(const MatrixXd_t &vA, const VectorXd_t &b, VectorXd_t &x, const value_t r = 0);

private:
    value_t decompositionLLT(const MatrixXd_t &vA, value_t damp);

    void solveEquByLLT(const VectorXd_t &b, VectorXd_t &x);

private:
    VectorXd_t b_;
    MatrixXd_t vL_;
};
}